package com.goke.media.call;

import android.content.Context;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.SoundPool;
import android.os.Build;

import com.goke.media.R;

import java.util.HashMap;

public class Sound {
    static HashMap<String, Integer> soundMap = new HashMap<String, Integer>();
    static SoundPool mSoundPool = null;

    public static void Create(Context ctx){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mSoundPool = new SoundPool.Builder()
                    .setMaxStreams(5)
                    .build();
        } else {
            mSoundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
        }

        soundMap.put("out", mSoundPool.load(ctx, R.raw.outgoing, 1));
        soundMap.put("in", mSoundPool.load(ctx, R.raw.incoming, 1));
    }
    static void StartPlay(String s) {
        mSoundPool.play(soundMap.get(s), 1, 1, 0, -1, 1);
    }

    static void StopPlay(){
        mSoundPool.autoPause();
        mSoundPool.stop(soundMap.get("in"));
        mSoundPool.stop(soundMap.get("out"));
    }
}

